/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * IngresoPlatoFuerte.java
 *
 * Created on 14-abr-2012, 23:34:25
 */

package gui;

import java.util.ListIterator;
import javax.swing.JOptionPane;
import modelo.Alimento;
import modelo.Cliente;
import modelo.Comida;
import modelo.Restaurante;

/**
 *
 * @author Lenovo
 */
public class IngresoPlatoFuerte extends javax.swing.JFrame {

    /** Creates new form IngresoPlatoFuerte */
    private Restaurante restaurante;
    private int mesaPedido;
    private int sillaPedido;
    private VentanaPrincipal v;
    public IngresoPlatoFuerte(Restaurante restaurante, int mesaPedido, int sillaPedido, VentanaPrincipal v) {
        initComponents();
        this.restaurante= restaurante;
        this.setLocationRelativeTo(null);
        this.mesaPedido=mesaPedido;
        this.sillaPedido=sillaPedido;
        this.v=v;
        cargarComboPlatosFuertes();
    }
    
    /**
     * carga los platos fuertes que hay en el restaurante en un combo
     */
    public void cargarComboPlatosFuertes() {
        jCBPlatoFuerte.removeAllItems();
        ListIterator<Alimento> iterator = restaurante.getMenu().listIterator();
        while (iterator.hasNext()) {
            Alimento a = iterator.next();
            if (a instanceof Comida) {
                Comida c = (Comida) a;
                if (c.getTipo().equals(Comida.TIPO_PLATO_FUERTE)) {
                    jCBPlatoFuerte.addItem(c.getNombre());
                }
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPPlatoFuerte = new javax.swing.JPanel();
        jLImgPlatoFuerte = new javax.swing.JLabel();
        jCBPlatoFuerte = new javax.swing.JComboBox();
        jLPlatoFuerte = new javax.swing.JLabel();
        jLCantPlatoFuerte = new javax.swing.JLabel();
        jSCantPlatoFuerte = new javax.swing.JSpinner();
        jBAgregarPlatoFuerte = new javax.swing.JButton();
        jBCancelarAgregarPlatoFuerte = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Restaurante \"Con Sabor\" - Adicionar Plato Fuerte");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPPlatoFuerte.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Plato Fuerte", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 14), new java.awt.Color(204, 0, 102))); // NOI18N

        jLImgPlatoFuerte.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/platosFuertes.jpg"))); // NOI18N
        jLImgPlatoFuerte.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jCBPlatoFuerte.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jCBPlatoFuerte.setForeground(new java.awt.Color(153, 0, 51));
        jCBPlatoFuerte.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione una opción" }));

        jLPlatoFuerte.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLPlatoFuerte.setForeground(new java.awt.Color(153, 0, 51));
        jLPlatoFuerte.setText("Plato Fuerte a ordenar:");

        jLCantPlatoFuerte.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLCantPlatoFuerte.setForeground(new java.awt.Color(153, 0, 51));
        jLCantPlatoFuerte.setText("Cantidad para este pedido:");

        javax.swing.GroupLayout jPPlatoFuerteLayout = new javax.swing.GroupLayout(jPPlatoFuerte);
        jPPlatoFuerte.setLayout(jPPlatoFuerteLayout);
        jPPlatoFuerteLayout.setHorizontalGroup(
            jPPlatoFuerteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPPlatoFuerteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLImgPlatoFuerte, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPPlatoFuerteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPPlatoFuerteLayout.createSequentialGroup()
                        .addComponent(jLPlatoFuerte)
                        .addGap(18, 18, 18)
                        .addComponent(jCBPlatoFuerte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPPlatoFuerteLayout.createSequentialGroup()
                        .addComponent(jLCantPlatoFuerte)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jSCantPlatoFuerte, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        jPPlatoFuerteLayout.setVerticalGroup(
            jPPlatoFuerteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPPlatoFuerteLayout.createSequentialGroup()
                .addGroup(jPPlatoFuerteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPPlatoFuerteLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPPlatoFuerteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLPlatoFuerte)
                            .addComponent(jCBPlatoFuerte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPPlatoFuerteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLCantPlatoFuerte)
                            .addComponent(jSCantPlatoFuerte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLImgPlatoFuerte, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jBAgregarPlatoFuerte.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBAgregarPlatoFuerte.setForeground(new java.awt.Color(204, 0, 102));
        jBAgregarPlatoFuerte.setText("AGREGAR PLATO FUERTE");
        jBAgregarPlatoFuerte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAgregarPlatoFuerteActionPerformed(evt);
            }
        });

        jBCancelarAgregarPlatoFuerte.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBCancelarAgregarPlatoFuerte.setForeground(new java.awt.Color(204, 0, 102));
        jBCancelarAgregarPlatoFuerte.setText("CANCELAR");
        jBCancelarAgregarPlatoFuerte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarAgregarPlatoFuerteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jPPlatoFuerte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(183, 183, 183)
                        .addComponent(jBAgregarPlatoFuerte)
                        .addGap(32, 32, 32)
                        .addComponent(jBCancelarAgregarPlatoFuerte)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jPPlatoFuerte, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBAgregarPlatoFuerte)
                    .addComponent(jBCancelarAgregarPlatoFuerte))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBAgregarPlatoFuerteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAgregarPlatoFuerteActionPerformed
      String alimento= (String)jCBPlatoFuerte.getSelectedItem();
     int cantidadPlatoFuerte= (Integer) jSCantPlatoFuerte.getValue();
     Alimento ali= restaurante.buscarAlimento(alimento);
     if(ali!=null){

         Cliente c = restaurante.getClientes()[mesaPedido][sillaPedido];
          String msj =c.modificarPedido(ali,cantidadPlatoFuerte);
          JOptionPane.showMessageDialog(null, msj);
        
        }else{
         JOptionPane.showMessageDialog(null, "Este alimento no esta disponible en el menu");
        
     }
    }//GEN-LAST:event_jBAgregarPlatoFuerteActionPerformed

    private void jBCancelarAgregarPlatoFuerteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarAgregarPlatoFuerteActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jBCancelarAgregarPlatoFuerteActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
        v.cargarConsumoActual();
    }//GEN-LAST:event_formWindowClosed

    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAgregarPlatoFuerte;
    private javax.swing.JButton jBCancelarAgregarPlatoFuerte;
    private javax.swing.JComboBox jCBPlatoFuerte;
    private javax.swing.JLabel jLCantPlatoFuerte;
    private javax.swing.JLabel jLImgPlatoFuerte;
    private javax.swing.JLabel jLPlatoFuerte;
    private javax.swing.JPanel jPPlatoFuerte;
    private javax.swing.JSpinner jSCantPlatoFuerte;
    // End of variables declaration//GEN-END:variables

}
